package com.example.music;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.provider.MediaStore;

import java.io.File;

public class MediaBean {
    public  String path;
    public  String filename;
    public String vauther;
    public  String songname;


    public String getVauther(Context context) {

        MediaMetadataRetriever retriever= new MediaMetadataRetriever();
        Uri uri = Uri.fromFile(new File(path));
        try {

            retriever.setDataSource(context,uri);
            vauther=retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);

        } finally {
            retriever.release(); // 必须释放
        }

        return vauther;
    }

    public String getSongname(Context context) {
        MediaMetadataRetriever retriever=new MediaMetadataRetriever();
        Uri uri = Uri.fromFile(new File(path));
        try {
        retriever.setDataSource(context,uri);
        songname=retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
        } finally {
            retriever.release(); // 必须释放
        }
        return songname;
    }


}
